<?php

namespace Albireo\FileSystem;

use Nette\Web\User;
use Nette\Object;

use \dibi;
use \InvalidStateException;

use \KernelAuthenticator;
use \KernelAcl;

use Celebrio\AccessControl\AclConstants;

/**
 * Creates and logs in the user.
 */
class TestUserLogging extends Object {

    public function getUser() {
        $user = new User();

        $handler = new KernelAuthenticator();
        $author = new KernelAcl();
        $user->setAuthenticationHandler($handler);
        $user->setAuthorizationHandler($author);
        try {
            $user->login(AclConstants::ROOT_USER, "albireo");
        } catch (InvalidStateException $e) {
            if (false === strpos($e->getMessage(), "Cannot regenerate session ID after HTTP headers have been sent")) {
                throw $e; // It's not about regenerating session ID, throw it up!
            }
        }
        
        return $user;
    }
    
}
?>
